/*******************************************************************************
 * 名称： 48. 旋转图像
 * 地址： https://leetcode.cn/problems/rotate-image/description/
 ******************************************************************************/

/**
 * @param {number[][]} matrix
 * @return {void} Do not return anything, modify matrix in-place instead.
 */
const rotate = (matrix) => {
  const rowLength = matrix.length;
  const colLength = matrix[0].length;

  for (let i = 0; i < rowLength; i++) {
    for (let j = i; j < colLength; j++) {
      const temp = matrix[i][j];
      matrix[i][j] = matrix[j][i];
      matrix[j][i] = temp;
    }
  }

  return matrix.map((item) => item.reverse());
};

module.exports = {
  name: '48. 旋转图像',
  testFc: rotate,
};
